package com.adcc.ags.cgw.healthcheck;

import com.adcc.ags.cgw.entity.user.UserInfo;
import com.adcc.ags.cgw.managed.proxy.UserProxy;
import com.adcc.utility.log.Log;
import com.codahale.metrics.health.HealthCheck;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Maps;

import java.util.Map;

/**
 * 用户状态监控
 */
public class UserHealthCheck extends HealthCheck{

    @Override
    protected Result check() {
        try {
            Map<String,Object> map = Maps.newHashMap();

            // 获取网关运行模式
            map.put("mode",UserProxy.getInstance().getGWMode());

            // 获取网关用户运行状态
            Map<String,UserInfo> user = UserProxy.getInstance().getUserInfoMap();
            map.put("userList",user);
            return Result.healthy(new ObjectMapper().writeValueAsString(map));
        } catch (Exception ex) {
            Log.error(UserHealthCheck.class.getName(),"check() error",ex);
            return Result.unhealthy(ex.fillInStackTrace());
        }
    }
}
